﻿$(document).ready(function () {
    //NotificationBox(); //trong file jsNotification
    $("#notificationBox .menu > li").click(function (e) {

        switch (e.target.id) {
            case "friendNotifications":
                //change status & style menu
                $("#friendNotifications").addClass("active");
                $("#friendNotifications").removeClass("notification");
                $("#courseNotifications").removeClass("active");
                $("#otherNotifications").removeClass("active");
                //display selected division, hide others
                $("div.friendNotifications").fadeIn();
                $("div.courseNotifications").css("display", "none");
                $("div.otherNotifications").css("display", "none");
                break;
            case "courseNotifications":
                //change status & style menu
                $("#friendNotifications").removeClass("active");
                $("#courseNotifications").addClass("active");
                $("#courseNotifications").removeClass("notification");
                $("#otherNotifications").removeClass("active");
                //display selected division, hide others
                $("div.courseNotifications").fadeIn();
                $("div.friendNotifications").css("display", "none");
                $("div.otherNotifications").css("display", "none");
                break;
            case "otherNotifications":
                //change status & style menu
                $("#friendNotifications").removeClass("active");
                $("#courseNotifications").removeClass("active");
                $("#otherNotifications").removeClass("notification");
                $("#otherNotifications").addClass("active");
                //display selected division, hide others
                $("div.otherNotifications").fadeIn();
                $("div.friendNotifications").css("display", "none");
                $("div.courseNotifications").css("display", "none");
                break;
        }
        //alert(e.target.id);
        return false;
    });
    GetNotificationPaging(1);
    $("#notificationBox .menu > li").click(function (e) {
        switch (e.target.id) {
            case "friendNotifications":
                $("input[name=typeNotification]").val("friend");
                if ($(this).attr("loaded") == "false") {
                    $(this).attr("loaded", "true");
                    GetNotificationPaging(1);
                }
                break;
            case "otherNotifications":
                $("input[name=typeNotification]").val("other");
                if ($(this).attr("loaded") == "false") {
                    $(this).attr("loaded", "true");
                    GetNotificationPaging(1);
                }
                break;
            case "courseNotifications":
                $("input[name=typeNotification]").val("course");
                if ($(this).attr("loaded") == "false") {
                    $(this).attr("loaded", "true");
                    GetNotificationPaging(1);
                }
                break;
        }
    });
    $("li[NotificationID]").live({
        'mouseenter': function () {
            $(this).find("a[name=checkNotification]").css('display', 'block');
        },
        'mouseleave': function () {
            $(this).find("a[name=checkNotification]").css('display', 'none');
        }
    });

    $("ul.pager li a").live('click', function () {
        GetNotificationPaging($(this).attr("page"));
        return false;
    });
});
function GetNotificationPaging(page) {
    var typeNotification = $("input[name=typeNotification]").val();
    $.post("/Notification/PagingNotification/", { 'type': typeNotification, 'page': page }, function (data) {
        if ($(data).find("p[name=noMore]").length != 0) {
            switch (typeNotification) {
                case "friend":
                    $(".friendNotifications").append("<p style='padding-left:10px'>Không có thông báo nào<p>");
                    break;
                case "other":
                    $(".otherNotifications").append("<p style='padding-left:10px'>Không có thông báo nào<p>");
                    break;
                case "course":
                    $(".courseNotifications").append("<p style='padding-left:10px'>Không có thông báo nào<p>");
                    break;
            }
        }
        else {
            switch (typeNotification) {
                case "friend":
                    $(".friendNotifications").html(data);
                    break;
                case "other":
                    $(".otherNotifications").html(data);
                    break;
                case "course":
                    $(".courseNotifications").html(data);
                    break;
            }
        }
    })
}

//function HasReadNotification(notificationID, type, $this) {
//    var item = $($this);
//    $.post("/Notification/HasReadNotification", { 'notificationID': notificationID, 'type': type }, function (data) {
//        if (data == "success") {
//            item.remove();
//        }
//        else {
//            alert("Có lỗi, refresh trình duyệt và thử lại sau");
//        }
//    })
//}
